<!DOCTYPE html>
<html lang="en">
<head>
    {{include file="lib/page_head" /}}

    <style>
        table th{word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        table td{word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        .from_table .td_l,.from_table .td_r{font-size:14px!important;line-height: 25px;word-wrap:break-word;word-break:break-all}
        #search_form .form-control,#search_form .select5{width:100px;height:28px;padding:5px;}
        #search_form .layui-input-inline{width:auto;margin: 0;}
        #search_form .form-group{margin-right:0;margin-bottom: 5px;}
        #search_form .btn{height:30px;line-height:30px;padding:0 10px;}
    </style>
</head>

<body>



<!-- Preloader -->
<div id="preloader">
    <div id="status"><i class="fa fa-spinner fa-spin"></i></div>
</div>

<section>
    {{include file="lib/page_left" /}}
    <div class="mainpanel">

        {{include file="lib/page_header" /}}

        <div class="contentpanel" >
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="panel-close">×</a>
                        <a href="" class="minimize">−</a>
                    </div>
                    <h4 class="panel-title">柴油卡申请列表</h4>
                </div>
                <div class="panel-body ">
                    <div id="info_list" class="form-inline">
                        <div class="btn-group">
                            <button class="btn btn-primary" onclick="edit_info(0)">添加</button>
                            <!--<button class="btn btn-primary" onclick="add_list()">批量添加</button>-->
                            <!--<button class="btn btn-primary" onclick="del_info(0)">删除</button>-->
                            <!--<button class="btn btn-primary" onclick="set_cancel(0)">取消</button>-->
                            <button class="btn btn-primary" onclick="location.href = location.href;">刷新</button>

                        </div>
                        <div class="layui-form-item search_tools" style="margin-top:10px;" >
                            <form class="layui-form" id="search_form" action="" onsubmit="return false;">

                                <div class="form-group">
                                    <label >身份证号</label>
                                    <input class="form-control" name="cert_no"  autocomplete="off" type="text">
                                </div>

                                <div  class="form-group">
                                    <label > 状态</label>
                                    <select class="select5" name="status">
                                        <option value="-1">状态</option>
                                        <option value="0">未审核</option>
                                        <option value="1">审核中</option>
                                        <option value="2">审核成功</option>
                                        <option value="3">审核失败</option>
                                    </select>
                                </div>


                                <div style="display: inline-block;clear: both;">
                                    <button class="btn btn-primary" onclick="search()">查询</button>
                                    <button class="btn btn-default" onclick="search_reset()">取消</button>
                                </div>
                            </form>
                            <div class="well well-sm search_toogle"><span class="glyphicon glyphicon-chevron-down"></span></div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- contentpanel -->

    </div><!-- mainpanel -->
    {{include file="lib/page_right" /}}
</section>

<div id="edit_info" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="id" value="0">
            <div  class="form-group">
                <label >企业用户<span style="color:red;">*</span></label>
                <select class="select5" name="company_id" data-search="true">
                    <option value="">请选择</option>
                    {{foreach $company_list as $val }}
                    <option value="{{$val.id}}">{{$val.name}}({{$val.id}})</option>
                    {{/foreach}}
                </select>
            </div>
            <div  class="form-group">
                <label > 身份证号<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="请输入身份证号" name="card_id" type="text">
            </div>
            <div  class="form-group">
                <label > 车牌号<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="请输入车牌号" name="plate_number" type="text">
            </div>

            <div  class="form-group">
                <label >身份证正面照片<span style="color:red;">*</span></label>
                <div>
                    <input type="hidden" name="card_img_url_1" class="upload_file_obj"  placeholder="请上传身份证正面照片">
                    <a class="btn btn-success upload_file">上传身份证正面照片</a>
                    <div style="display: none;padding:10px;">
                        <img src="" class="upload_file_img" style="max-width:280px;">
                    </div>
                </div>
            </div>
            <div  class="form-group">
                <label >身份证背面照片<span style="color:red;">*</span></label>
                <div>
                    <input type="hidden" name="card_img_url_2" class="upload_file_obj"  placeholder="请上传身份证背面照片">
                    <a class="btn btn-success upload_file">上传身份证背面照片</a>
                    <div style="display: none;padding:10px;">
                        <img src="" class="upload_file_img" style="max-width:280px;">
                    </div>
                </div>
            </div>
            <div  class="form-group">
                <label >行使证正面照片<span style="color:red;">*</span></label>
                <div>
                    <input type="hidden" name="driving_img_url_1" class="upload_file_obj"  placeholder="请上传行使证正面照片">
                    <a class="btn btn-success upload_file">上传行使证正面照片</a>
                    <div style="display: none;padding:10px;">
                        <img src="" class="upload_file_img" style="max-width:280px;">
                    </div>
                </div>
            </div>
            <div  class="form-group">
                <label >行使证背面照片<span style="color:red;">*</span></label>
                <div>
                    <input type="hidden" name="driving_img_url_2" class="upload_file_obj"  placeholder="请上传行使证背面照片">
                    <a class="btn btn-success upload_file">上传行使证背面照片</a>
                    <div style="display: none;padding:10px;">
                        <img src="" class="upload_file_img" style="max-width:280px;">
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="add_approval_id" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="id" value="0">
            <div  class="form-group">
                <label >审核证明ID<span style="color:red;">*</span></label>
                <select class="select5" name="approval_id" data-search="true">
                    <option value="">请选择</option>
                    {{foreach $apply_id_list as $val }}
                    <option value="{{$val.approval_id}}" data-approvalImg="{{$val.approvalImg}}">{{$val.provider}}({{$val.approval_id}})</option>
                    {{/foreach}}
                </select>
            </div>
            <div class="form-group">
                <div style="margin:8px 5px;height:100px;text-align: center;" class="img_list">

                </div>

            </div>
        </form>
    </div>
</div>
<script src="../js/jquery-1.11.1.min.js"></script>
<script src="../js/jquery-migrate-1.2.1.min.js"></script>
<script src="../js/jquery-ui-1.10.3.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery.sparkline.min.js"></script>
<script src="../js/toggles.min.js"></script>
<script src="../js/jquery.cookies.js"></script>
<script src="../js/jquery.tmpl.js"></script>
<script src="../js/custom.js"></script>
<script src="../layui/layui.js"></script>
<script src="../js/jquery.gritter.min.js"></script>
<script src="../js/form.beautify.js?t={{$version}}"></script>
<script src="../js/commen.js?t={{$version}}"></script>
<script src="../js/datatables.js?t={{$version}}"></script>
<link href="../css/ley.dialog.css" rel="stylesheet">
<script src="../js/ley.dialog.js?t={{$version}}"></script>
<script>
    layui.use(['laydate','laypage',"element","upload"], function(){
        var  upload = layui.upload;
        upload.render({
            elem: '.upload_file' //绑定元素
            ,url: '/upload/upload_img' //上传接口
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }

            ,done: function(res, index, upload){
                layer.closeAll('loading');
                if(res.code != 0 )
                {
                    layer.msg(res.msg,{zIndex: layer.zIndex});
                }else{
                    var path = res.data.path;
                    var url = res.data.url;
                    // $(this.item).next().val(path);
                    $(this.item).parent().find(".upload_file_obj").val(path)
                    $(this.item).parent().find(".upload_file_img").attr("src",url).parent().show();
                    // $(item).parent().find(".upload_file_img").attr("src",url);
                    $(this.item).parents(".form-group").removeClass("has-error");
                }

                //上传完毕回调
            }
            ,error: function(index, upload){
                //请求异常回调
                layer.closeAll('loading');
            }
        });

        $("body").on("change",".upload_file_obj",function () {
            var file = this.files[0];
            if(file.size > 60*1024)
            {
                layer.msg("文件大于60KB",{zIndex: layer.zIndex});
                clearFile($(this));
                $(this).next().hide();
                return false;
            }
            if(!/image\/(gif|jpg|jpeg|png|gif|jpg|png)$/.test(file.type)){
                layer.msg("图片类型不正确",{zIndex: layer.zIndex});
                clearFile($(this));
                $(this).next().hide();
                return false;
            }

            var objUrl = getObjectURL(file) ;
            $(this).next().find("img").attr("src",objUrl).parent().show();

        });

    });
    var admin_id = "{{$ADMIN_ID}}";

    $(function () {


        $("#info_list").datatables({
            idField: 'id',
            mobile_field:["ck","plate_number","status"],
            columns:[
                {field:'ck',checkbox:true },
                {field:'id',title:'编号',width:50}
                ,{field:'name',width:120,  title: '企业用户'}
                ,{field:'card_id',width:120,  title: '身份证号'}
                ,{field:'plate_number',width:120,  title: '车牌号'}

                , {field:'card_img_url_1',title:'身份证正面照片',width:100,formatter:function (value,row,index){
                        if(value)
                        {
                            return "<a href='/upload/show/path/"+value.replace(/\//g,"@")+"' target='_blank'>查看</a>";
                        }
                    }}
                , {field:'card_img_url_2',title:'身份证背面照片',width:100,formatter:function (value,row,index){
                        if(value)
                        {
                            return "<a href='/upload/show/path/"+value.replace(/\//g,"@")+"' target='_blank'>查看</a>";
                        }
                    }}
                , {field:'driving_img_url_1',title:'行使证正面照片',width:100,formatter:function (value,row,index){
                        if(value)
                        {
                            return "<a href='/upload/show/path/"+value.replace(/\//g,"@")+"' target='_blank'>查看</a>";
                        }
                    }}
                , {field:'driving_img_url_2',title:'行使证背面照片',width:100,formatter:function (value,row,index){
                        if(value)
                        {
                            return "<a href='/upload/show/path/"+value.replace(/\//g,"@")+"' target='_blank'>查看</a>";
                        }
                    }}
                , {field:'approval_id',title:'审批证明ID',width:100}
                , {field:'card_no',title:'申请卡号',width:100}
                , {field:'status',title:'状态',width:30,formatter:function (value,row,index) {
                        if(value===1){
                            return "已提交";
                        }else if(value===2){
                            return "审核成功";
                        }else if(value===3){
                            return "审核失败";
                        }else{
                            return "未提交";
                        }
                    }}
                , {field:'ctime',title:'时间',width:50, formatter: function (value, row, index) {return getLocalTime(value) + "";}}
                , {field:'operation',title:'操作',width:30,formatter:function (value,row,index) {
                        var text = "";
                        text += '<div class="btn-group"> ';
                        text += '<a data-toggle="dropdown" class="dropdown-toggle"> ';
                        text += '<i class="fa fa-cog"></i> ';
                        text += '</a> ';
                        text += '<ul role="menu" class="dropdown-menu pull-right"> ';

                        if(!row.approval_id){
                            text +='<li><a href="javascript:void 0;" onclick="add_approval_id(\''+row.id+'\')">添加证明</a></li> ' ;
                        }
                        if(row.approval_id &&row.status == 0){
                            text +='<li><a href="javascript:void 0;" onclick="submit_apply(\''+row.id+'\')">提交申请</a></li> ' ;
                        }
                        text +='</ul> ';
                        text +='</div>';
                        return text;
                    }}


            ],
            ajax:{
                url:"/companys/ajax_apply_list",
                parems:get_search_data(),
                callback:function (msg) {
                    check_table_list_data(msg);
                    check_parent_height();
                }
            }

        });
    });

    function edit_info(id) {
        $("#edit_info form")[0].reset();
        $("#edit_info #product_list").empty();
        $("#edit_info").find("input[name='id']").val(0);
        $("#edit_info").find("input[name='card_no']").val("");
        $("#edit_info").find("select[name='status']").val(0).trigger("change");

        if(id)
        {
            AjaxCommen("GET","/card/ajax_card_info",{id:id},function (msg) {
                if (!msg.error)
                {
                    $("#edit_info input[type!='radio'],#edit_info select,#edit_info textarea").each(function () {
                        var name = $(this).attr("name");

                        if(name&&msg.data[name]!==undefined)
                        {
                            $(this).val(msg.data[name]);
                        }

                        if($(this).is("select"))
                        {
                            $(this).trigger("change");
                        }
                    });
                    if(msg.data.status != 0)
                    {
                        $("#edit_info select[name='status']")[0].disabled = true;
                        $("#edit_info select[name='status']").trigger("change");

                    }
                    $("#edit_info input[name='id']").val(msg.data.id);


                    open_info();
                }
            });
        }else{

            open_info();
        }
    }
    function open_info()
    {
        $("#edit_info select").trigger("change");
        openDialog2({title:"申请审核证明",area: ['300', "500"],content:$("#edit_info"),clone:true,before:function (layero) {

            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;

                $("#edit_info input[type!='radio'],#edit_info select,#edit_info textarea,#edit_info input[type='radio']:checked",layero).each(function () {
                    var name = $(this).attr("name");

                    if(name)
                    {
                        var value = $(this).val();
                        var type = $(this).attr("type");
                        var ignore = $(this).attr("data-ignore");
                        if(type !== "file")
                        {

                            if(value)
                            {
                                data[name] = value;

                                $(this).parents(".form-group").removeClass("has-error");
                            }else{

                                if (ignore != "true")
                                {
                                    $(this).parents(".form-group").addClass("has-error");
                                    is_false = true;
                                }
                            }
                        }
                    }
                });
                if(is_false)
                {
                    return false;
                }
                AjaxCommen("GET","/companys/ajax_apply_save",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }
    function add_approval_id(id)
    {
        openDialog2({title:"审核证明",area: ['300', "500"],content:$("#add_approval_id"),clone:true,before:function (layero) {
                $("select[name='approval_id']",layero).change(function(){
                    if($(this).val())
                    {
                        $(".img_list",layero).empty();
                        var approvalImg = $(this).find("option:checked").attr("data-approvalImg");
                        approvalImg = approvalImg.replace(/\//g, '@');
                        var url = "/upload/show/path/"+approvalImg;
                        $(".img_list",layero).append("<a href='"+url+"' target='_blank'><img src='"+url+"' style='max-width:100px;max-height:100px;margin: 0 auto;'/></a>");
                    }
                });
            },
            yes:function (index,layero) {
                var data = {id:id};
                var approval_id = $("select[name='approval_id']",layero).val();
                if(!approval_id)
                {
                    openMsg("请选择审核证明ID");
                    return ;
                }
                data["approval_id"] = approval_id;
                AjaxCommen("GET","/companys/ajax_add_approval_id",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }
    function submit_apply(id)
    {
        promptMsg("确认提交吗?",function(){
            AjaxCommen("GET","/companys/ajax_apply_submit",{id:id},function (msg) {
                if(msg.error === 0)
                {
                    openMsg("成功");
                    search();
                }
            });
        });
    }
    function search()
    {
        var data = get_search_data();
        console.log(data);
        $("#info_list").setParems(data);
        $("#info_list").reload();

    }
    function search_reset() {
        $("#search_form")[0].reset();
        search();
    }
    function get_search_data() {
        var data = {};
        $('#search_form select,#search_form input').each(function () {
            var name = $(this).attr("name");
            if(name)
            {
                data[name] = $(this).val();
            }

        });
        return data;
    }
</script>

</body>
</html>
